package com.timoon.sample.dao;

import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.timoon.component.panel.jqgrid.JqGridParameter;
import com.timoon.sample.dao.model.TUser;
import com.timoon.sample.dao.model.TUserExample;

@Repository(value="tUserDAOImpl")
public class TUserDAOImpl extends SqlMapClientDaoSupport implements TUserDAO {

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table t_user
	 * @abatorgenerated  Tue Jun 11 14:05:08 CST 2013
	 */
	public TUserDAOImpl() {
		super();
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table t_user
	 * @abatorgenerated  Tue Jun 11 14:05:08 CST 2013
	 */
	public void insert(TUser record) {
		getSqlMapClientTemplate().insert("t_user.abatorgenerated_insert",
				record);
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table t_user
	 * @abatorgenerated  Tue Jun 11 14:05:08 CST 2013
	 */
	public int updateByPrimaryKey(TUser record) {
		int rows = getSqlMapClientTemplate().update(
				"t_user.abatorgenerated_updateByPrimaryKey", record);
		return rows;
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table t_user
	 * @abatorgenerated  Tue Jun 11 14:05:08 CST 2013
	 */
	public int updateByPrimaryKeySelective(TUser record) {
		int rows = getSqlMapClientTemplate().update(
				"t_user.abatorgenerated_updateByPrimaryKeySelective", record);
		return rows;
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table t_user
	 * @abatorgenerated  Tue Jun 11 14:05:08 CST 2013
	 */
	public List selectByExample(TUserExample example) {
		List list = getSqlMapClientTemplate().queryForList(
				"t_user.abatorgenerated_selectByExample", example);
		return list;
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table t_user
	 * @abatorgenerated  Tue Jun 11 14:05:08 CST 2013
	 */
	public TUser selectByPrimaryKey(Integer id) {
		TUser key = new TUser();
		key.setId(id);
		TUser record = (TUser) getSqlMapClientTemplate().queryForObject(
				"t_user.abatorgenerated_selectByPrimaryKey", key);
		return record;
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table t_user
	 * @abatorgenerated  Tue Jun 11 14:05:08 CST 2013
	 */
	public int deleteByExample(TUserExample example) {
		int rows = getSqlMapClientTemplate().delete(
				"t_user.abatorgenerated_deleteByExample", example);
		return rows;
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table t_user
	 * @abatorgenerated  Tue Jun 11 14:05:08 CST 2013
	 */
	public int deleteByPrimaryKey(Integer id) {
		TUser key = new TUser();
		key.setId(id);
		int rows = getSqlMapClientTemplate().delete(
				"t_user.abatorgenerated_deleteByPrimaryKey", key);
		return rows;
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table t_user
	 * @abatorgenerated  Tue Jun 11 14:05:08 CST 2013
	 */
	public int countByExample(TUserExample example) {
		Integer count = (Integer) getSqlMapClientTemplate().queryForObject(
				"t_user.abatorgenerated_countByExample", example);
		return count.intValue();
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table t_user
	 * @abatorgenerated  Tue Jun 11 14:05:08 CST 2013
	 */
	public int updateByExampleSelective(TUser record, TUserExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"t_user.abatorgenerated_updateByExampleSelective", parms);
		return rows;
	}

	/**
	 * This method was generated by Abator for iBATIS. This method corresponds to the database table t_user
	 * @abatorgenerated  Tue Jun 11 14:05:08 CST 2013
	 */
	public int updateByExample(TUser record, TUserExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"t_user.abatorgenerated_updateByExample", parms);
		return rows;
	}

	/**
	 * This class was generated by Abator for iBATIS. This class corresponds to the database table t_user
	 * @abatorgenerated  Tue Jun 11 14:05:08 CST 2013
	 */
	private static class UpdateByExampleParms extends TUserExample {
		private Object record;

		public UpdateByExampleParms(Object record, TUserExample example) {
			super(example);
			this.record = record;
		}

		public Object getRecord() {
			return record;
		}
	}

	@Resource(name="sqlMapClient")
	private SqlMapClient sqlMapClient;
	
	@PostConstruct
	public void addSqlMapClient() {
		// TODO Auto-generated constructor stub
		this.setSqlMapClient(sqlMapClient);
	}
	
    @Override
	public List<Map<String, Object>> pageUser(JqGridParameter param) {
		// TODO Auto-generated method stub
		return this.getSqlMapClientTemplate().queryForList("t_user.pageUser",param);
	}

	@Override
	public Integer countUserForPage(JqGridParameter param) {
		// TODO Auto-generated method stub
		return (Integer) this.getSqlMapClientTemplate().queryForObject("t_user.countUserForPage",param);
	}

	/**
	 * ???user??????????????
	 */
	@Override
	public List<com.timoon.sample.dao.model.Resource> getResourcesByUserId(TUser user) {
		// TODO Auto-generated method stub
		return this.getSqlMapClientTemplate().queryForList("t_user.getResourcesByUserId", user);
	}

	@Override
	public Integer getIdByAccountName(TUser user) {
		// TODO Auto-generated method stub
		List<Integer> ids=this.getSqlMapClientTemplate().queryForList("t_user.getIdByAccountName",user);
		return ids.get(0);
	}
}